
package com.lucky.back.service.impl;
import com.lucky.back.ex.ServiceException;
import com.lucky.back.mapper.StoreupMapper;
import com.lucky.back.pojo.dto.StoreupAddNewDTO;
import com.lucky.back.pojo.entity.Storeup;
import com.lucky.back.pojo.vo.BannerListItemVO;
import com.lucky.back.pojo.vo.CartStandardVO;
import com.lucky.back.pojo.vo.StoreupListItemVO;
import com.lucky.back.pojo.vo.StoreupStandardVO;
import com.lucky.back.service.IStoreupService;
import com.lucky.back.web.ServiceCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Slf4j
@Service
public class StoreupServiceImpl implements IStoreupService {
    @Autowired
    StoreupMapper storeupMapper;


    @Override
    public void addNew(StoreupAddNewDTO storeupAddNewDTO) {
        log.debug("张敏瑞");
        String name = storeupAddNewDTO.getName();
        System.out.println("brandAddNewDTO = " + storeupAddNewDTO);
        int count = storeupMapper.countByName(name);
        if (count != 0){
            throw new ServiceException(ServiceCode.ERR_CONFLICT,"添加收藏失败,尝试添加的收藏名称以被占用");
        }
        Storeup brand = new Storeup();
        BeanUtils.copyProperties(storeupAddNewDTO,brand);
        storeupMapper.insert(brand);
    }


    @Override
    public List<StoreupListItemVO> list() {
        log.debug("开始处理[业务查询列表]的业务");
        return storeupMapper.list();
    }

    @Override
    public void delete(Long id) {
        log.debug("开始处理剩余收藏的请求.参数={}",id);
        StoreupStandardVO queryResult = storeupMapper.getStandardById(id);
        if (queryResult == null){
            throw new ServiceException(ServiceCode.ERR_NOT_FOUND,"删除收藏失败,删除的数据不存在");
        }
        log.debug("即将删除出数据");
        storeupMapper.deleteById(id);
        log.debug("删除完成!");
    }

    @Override
    public void deleteByIds(List<Long> list) {
        log.debug("开始处理删除请求");
        storeupMapper.deleteByIds(list);
        log.debug("删除分类，完成！");
    }
}

